home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / tests / fstrash / fsSetFD.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-10  |  31.8 KB  |  1,195 lines

  1. /* 
  2.  * fsSetFd.c --
  3.  *
  4.  *    These are the routines that fill in the file descriptors of the files
  5.  *    in the file system.
  6.  *
  7.  * Copyright 1989 Regents of the University of California
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software and its documentation for any purpose and without
  10.  * fee is hereby granted, provided that the above copyright
  11.  * notice appear in all copies.  The University of California
  12.  * makes no representations about the suitability of this
  13.  * software for any purpose.  It is provided "as is" without
  14.  * express or implied warranty.
  15.  */
  16.  
  17. #ifndef lint
  18. static char rcsid[] = "$Header: /sprite/lib/forms/RCS/proto.c,v 1.2 89/01/07 04:12:18 rab Exp $ SPRITE (Berkeley)";
  19. #endif /* not lint */
  20.  
  21. #include "sprite.h"
  22. #include "option.h"
  23. #include "disk.h"
  24. #include <stdio.h>
  25. #include <sys/file.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28.  
  29. extern Boolean rootFree;
  30. extern Boolean rootFile;
  31. extern Boolean noRoot;
  32.  
  33.  
  34. /*
  35.  *----------------------------------------------------------------------
  36.  *
  37.  * SetRootFileDescriptor --
  38.  *
  39.  *    File 2.
  40.  *    Set up the file descriptor for the root directory. The root
  41.  *    directory uses block 0.
  42.  *
  43.  * Results:
  44.  *    Fill in the file descriptor.
  45.  *
  46.  * Side effects:
  47.  *    None.
  48.  *
  49.  *----------------------------------------------------------------------
  50.  */
  51. void
  52. SetRootFileDescriptor(fileDescPtr)
  53.     register Fsdm_FileDescriptor *fileDescPtr;
  54. {
  55.     Time time;
  56.     int index;
  57.  
  58.     if (noRoot) {
  59.     bzero((Address) fileDescPtr, sizeof(Fsdm_FileDescriptor));
  60.     return;
  61.     }
  62.     fileDescPtr->flags = rootFree ? FSDM_FD_FREE :  FSDM_FD_ALLOC;
  63.     fileDescPtr->fileType = rootFile ? FS_FILE : FS_DIRECTORY;
  64.     fileDescPtr->permissions = 0755;
  65.     fileDescPtr->uid = 0;
  66.     fileDescPtr->gid = 0;
  67.     fileDescPtr->lastByte = FS_BLOCK_SIZE-1;
  68.     fileDescPtr->firstByte = -1;
  69.     fileDescPtr->numLinks = 3;
  70.     /*
  71.      * Can't know device information because that depends on
  72.      * the way the system is configured.
  73.      */
  74.     fileDescPtr->devServerID = -1;
  75.     fileDescPtr->devType = -1;
  76.     fileDescPtr->devUnit = -1;
  77.  
  78.     /*
  79.      * Set the time stamps.  This assumes that universal time, not local
  80.      * time, is used for time stamps.
  81.      */
  82.     Sys_GetTimeOfDay(&time, NULL, NULL);
  83.     fileDescPtr->createTime = time.seconds;
  84.     fileDescPtr->accessTime = 0;
  85.     fileDescPtr->descModifyTime = time.seconds;
  86.     fileDescPtr->dataModifyTime = time.seconds;
  87.  
  88.     /*
  89.      * Place the data in the first filesystem block.
  90.      */
  91.     fileDescPtr->direct[0] = 0;
  92.     for (index = 1; index < FSDM_NUM_DIRECT_BLOCKS ; index++) {
  93.     fileDescPtr->direct[index] = FSDM_NIL_INDEX;
  94.     }
  95.     for (index = 0; index < FSDM_NUM_INDIRECT_BLOCKS ; index++) {
  96.     fileDescPtr->indirect[index] = FSDM_NIL_INDEX;
  97.     }
  98.     fileDescPtr->numKbytes = 4;
  99.     fileDescPtr->version = 1;
  100. }
  101.  
  102. /*
  103.  *----------------------------------------------------------------------
  104.  *
  105.  * SetBadBlockFileDescriptor --
  106.  *
  107.  *    File 1.
  108.  *    Set up the file descriptor for the bad block file.
  109.  *
  110.  * Results:
  111.  *    Fill in the file descriptor.
  112.  *
  113.  * Side effects:
  114.  *    None.
  115.  *
  116.  *----------------------------------------------------------------------
  117.  */
  118. void
  119. SetBadBlockFileDescriptor(fileDescPtr)
  120.     register Fsdm_FileDescriptor *fileDescPtr;
  121. {
  122.     Time time;
  123.     int index;
  124.  
  125.     fileDescPtr->flags = FSDM_FD_ALLOC;
  126.     fileDescPtr->fileType = FS_FILE;
  127.     fileDescPtr->permissions = 0000;
  128.     fileDescPtr->uid = 0;
  129.     fileDescPtr->gid = 0;
  130.     fileDescPtr->lastByte = -1;
  131.     fileDescPtr->firstByte = -1;
  132.     fileDescPtr->numLinks = 0;        /* Intentionally unreferenced */
  133.     /*
  134.      * Can't know device information because that depends on
  135.      * the way the system is configured.
  136.      */
  137.     fileDescPtr->devServerID = -1;
  138.     fileDescPtr->devType = -1;
  139.     fileDescPtr->devUnit = -1;
  140.  
  141.     /*
  142.      * Set the time stamps.  This assumes that universal time, not local
  143.      * time, is used for time stamps.
  144.      */
  145.     Sys_GetTimeOfDay(&time, NULL, NULL);
  146.     fileDescPtr->createTime = time.seconds;
  147.     fileDescPtr->accessTime = 0;
  148.     fileDescPtr->descModifyTime = time.seconds;
  149.     fileDescPtr->dataModifyTime = time.seconds;
  150.  
  151.     /*
  152.      * Place the data in the first filesystem block.
  153.      */
  154.     for (index = 0; index < FSDM_NUM_DIRECT_BLOCKS ; index++) {
  155.     fileDescPtr->direct[index] = FSDM_NIL_INDEX;
  156.     }
  157.     for (index = 0; index < FSDM_NUM_INDIRECT_BLOCKS ; index++) {
  158.     fileDescPtr->indirect[index] = FSDM_NIL_INDEX;
  159.     }
  160.     fileDescPtr->numKbytes = 0;
  161.     fileDescPtr->version = 1;
  162. }
  163.  
  164. /*
  165.  *----------------------------------------------------------------------
  166.  *
  167.  * SetLostFoundFileDescriptor --
  168.  *
  169.  *    File 3.
  170.  *    Set up the file descriptor for the lost and found directory.
  171.  *
  172.  * Results:
  173.  *    Fill in the file descriptor.
  174.  *
  175.  * Side effects:
  176.  *    None.
  177.  *
  178.  *----------------------------------------------------------------------
  179.  */
  180. void
  181. SetLostFoundFileDescriptor(fileDescPtr)
  182.     register Fsdm_FileDescriptor *fileDescPtr;
  183. {
  184.     Time time;
  185.     int index;
  186.  
  187.     fileDescPtr->flags = FSDM_FD_ALLOC;
  188.     fileDescPtr->fileType = FS_DIRECTORY;
  189.     fileDescPtr->permissions = 0755;
  190.     fileDescPtr->uid = 0;
  191.     fileDescPtr->gid = 0;
  192.     fileDescPtr->lastByte = FSDM_NUM_LOST_FOUND_BLOCKS * FS_BLOCK_SIZE - 1;
  193.     fileDescPtr->firstByte = -1;
  194.     fileDescPtr->numLinks = 2;
  195.     /*
  196.      * Can't know device information because that depends on
  197.      * the way the system is configured.
  198.      */
  199.     fileDescPtr->devServerID = -1;
  200.     fileDescPtr->devType = -1;
  201.     fileDescPtr->devUnit = -1;
  202.  
  203.     /*
  204.      * Set the time stamps.  This assumes that universal time, not local
  205.      * time, is used for time stamps.
  206.      */
  207.     Sys_GetTimeOfDay(&time, NULL, NULL);
  208.     fileDescPtr->createTime = time.seconds;
  209.     fileDescPtr->accessTime = 0;
  210.     fileDescPtr->descModifyTime = time.seconds;
  211.     fileDescPtr->dataModifyTime = time.seconds;
  212.  
  213.     for (index = 0; index < FSDM_NUM_LOST_FOUND_BLOCKS ; index++) {
  214.     fileDescPtr->direct[index] = FS_FRAGMENTS_PER_BLOCK * (index + 1);
  215.     }
  216.     for (; index < FSDM_NUM_DIRECT_BLOCKS ; index++) {
  217.     fileDescPtr->direct[index] = FSDM_NIL_INDEX;
  218.     }
  219.     for (index = 0; index < FSDM_NUM_INDIRECT_BLOCKS ; index++) {
  220.     fileDescPtr->indirect[index] = FSDM_NIL_INDEX;
  221.     }
  222.     fileDescPtr->numKbytes = 8;
  223.     fileDescPtr->version = 1;
  224. }
  225.  
  226. /*
  227.  *----------------------------------------------------------------------
  228.  *
  229.  * SetEmptyFileDescriptor --
  230.  *
  231.  *    File 4
  232.  *    Set up a file descriptor for an empty file.
  233.  *
  234.  * Results:
  235.  *    Fill in the file descriptor.
  236.  *
  237.  * Side effects:
  238.  *    None.
  239.  *
  240.  *----------------------------------------------------------------------
  241.  */
  242. void
  243. SetEmptyFileDescriptor(fileDescPtr)
  244.     register Fsdm_FileDescriptor *fileDescPtr;
  245. {
  246.     Time time;
  247.     int index;
  248.  
  249.     fileDescPtr->flags = FSDM_FD_ALLOC;
  250.     fileDescPtr->fileType = FS_FILE;
  251.     fileDescPtr->permissions = 0666;
  252.     fileDescPtr->uid = 0;
  253.     fileDescPtr->gid = 0;
  254.     fileDescPtr->lastByte = -1;
  255.     fileDescPtr->firstByte = -1;
  256.     fileDescPtr->numLinks = 1;
  257.     /*
  258.      * Can't know device information because that depends on
  259.      * the way the system is configured.
  260.      */
  261.     fileDescPtr->devServerID = -1;
  262.     fileDescPtr->devType = -1;
  263.     fileDescPtr->devUnit = -1;
  264.  
  265.     /*
  266.      * Set the time stamps.  This assumes that universal time, not local
  267.      * time, is used for time stamps.
  268.      */
  269.     Sys_GetTimeOfDay(&time, NULL, NULL);
  270.     fileDescPtr->createTime = time.seconds;
  271.     fileDescPtr->accessTime = 0;
  272.     fileDescPtr->descModifyTime = time.seconds;
  273.     fileDescPtr->dataModifyTime = time.seconds;
  274.  
  275.     for (index = 0; index < FSDM_NUM_DIRECT_BLOCKS ; index++) {
  276.     fileDescPtr->direct[index] = FSDM_NIL_INDEX;
  277.     }
  278.     for (index = 0; index < FSDM_NUM_INDIRECT_BLOCKS ; index++) {
  279.     fileDescPtr->indirect[index] = FSDM_NIL_INDEX;
  280.     }
  281.     fileDescPtr->numKbytes = 0;
  282.     fileDescPtr->version = 1;
  283. }
  284. /*
  285.  *----------------------------------------------------------------------
  286.  *
  287.  * SetTooBigFD --
  288.  *
  289.  *    File 6
  290.  *    The file size is bigger than the number of blocks.
  291.  *    The block count is too large.
  292.  *
  293.  * Results:
  294.  *    Fill in the file descriptor.
  295.  *
  296.  * Side effects:
  297.  *    None.
  298.  *
  299.  *----------------------------------------------------------------------
  300.  */
  301. void
  302. SetTooBigFD(fileDescPtr)
  303.     register Fsdm_FileDescriptor *fileDescPtr;
  304. {
  305.     Time time;
  306.     int index;
  307.     int numBlocks = 1;
  308.     int start;
  309.  
  310.  
  311.     fileDescPtr->flags = FSDM_FD_ALLOC;
  312.     fileDescPtr->fileType = FS_FILE;
  313.     fileDescPtr->permissions = 0755;
  314.     fileDescPtr->uid = 0;
  315.     fileDescPtr->gid = 0;
  316.     fileDescPtr->lastByte = numBlocks * FS_BLOCK_SIZE + 10;
  317.     fileDescPtr->firstByte = -1;
  318.     fileDescPtr->numLinks = 2;
  319.     /*
  320.      * Can't know device information because that depends on
  321.      * the way the system is configured.
  322.      */
  323.     fileDescPtr->devServerID = -1;
  324.     fileDescPtr->devType = -1;
  325.     fileDescPtr->devUnit = -1;
  326.  
  327.     /*
  328.      * Set the time stamps.  This assumes that universal time, not local
  329.      * time, is used for time stamps.
  330.      */
  331.     Sys_GetTimeOfDay(&time, NULL, NULL);
  332.     fileDescPtr->createTime = time.seconds;
  333.     fileDescPtr->accessTime = 0;
  334.     fileDescPtr->descModifyTime = time.seconds;
  335.     fileDescPtr->dataModifyTime = time.seconds;
  336.  
  337.     start = (FSDM_NUM_LOST_FOUND_BLOCKS + 1);
  338.  
  339.     for (index = 0; index < numBlocks ; index++) {
  340.     fileDescPtr->direct[index] = (start + index) * FS_FRAGMENTS_PER_BLOCK;
  341.     }
  342.     for (; index < FSDM_NUM_DIRECT_BLOCKS ; index++) {
  343.     fileDescPtr->direct[index] = FSDM_NIL_INDEX;
  344.     }
  345.     for (index = 0; index < FSDM_NUM_INDIRECT_BLOCKS ; index++) {
  346.     fileDescPtr->indirect[index] = FSDM_NIL_INDEX;
  347.     }
  348.     fileDescPtr->numKbytes = 8;
  349.     fileDescPtr->version = 1;
  350. }
  351.  
  352. /*
  353.  *----------------------------------------------------------------------
  354.  *
  355.  * SetTooSmallFD --
  356.  *
  357.  *     File 7
  358.  *    The file size is smaller than the number of blocks.
  359.  *
  360.  * Results:
  361.  *    None.
  362.  *
  363.  * Side effects:
  364.  *    None.
  365.  *
  366.  *----------------------------------------------------------------------
  367.  */
  368. void
  369. SetTooSmallFD(fileDescPtr)
  370.     register Fsdm_FileDescriptor *fileDescPtr;
  371. {
  372.     Time time;
  373.     int index;
  374.     int num1KBlocks = 2;
  375.     int start;
  376.  
  377.  
  378.     fileDescPtr->flags = FSDM_FD_ALLOC;
  379.     fileDescPtr->fileType = FS_FILE;
  380.     fileDescPtr->permissions = 0755;
  381.     fileDescPtr->uid = 0;
  382.     fileDescPtr->gid = 0;
  383.     fileDescPtr->lastByte = (num1KBlocks - 1) * 
  384.                 (FS_BLOCK_SIZE / FS_FRAGMENTS_PER_BLOCK) - 10;
  385.     fileDescPtr->firstByte = -1;
  386.     fileDescPtr->numLinks = 1;
  387.     /*
  388.      * Can't know device information because that depends on
  389.      * the way the system is configured.
  390.      */
  391.     fileDescPtr->devServerID = -1;
  392.     fileDescPtr->devType = -1;
  393.     fileDescPtr->devUnit = -1;
  394.  
  395.     /*
  396.      * Set the time stamps.  This assumes that universal time, not local
  397.      * time, is used for time stamps.
  398.      */
  399.     Sys_GetTimeOfDay(&time, NULL, NULL);
  400.     fileDescPtr->createTime = time.seconds;
  401.     fileDescPtr->accessTime = 0;
  402.     fileDescPtr->descModifyTime = time.seconds;
  403.     fileDescPtr->dataModifyTime = time.seconds;
  404.  
  405.     start = 16;
  406.  
  407.     for (index = 0; index < num1KBlocks ; index++) {
  408.     fileDescPtr->direct[index] = (start + index);
  409.     }
  410.     for (; index < FSDM_NUM_DIRECT_BLOCKS ; index++) {
  411.     fileDescPtr->direct[index] = FSDM_NIL_INDEX;
  412.     }
  413.     for (index = 0; index < FSDM_NUM_INDIRECT_BLOCKS ; index++) {
  414.     fileDescPtr->indirect[index] = FSDM_NIL_INDEX;
  415.     }
  416.     fileDescPtr->numKbytes = 2;
  417.     fileDescPtr->version = 1;
  418. }
  419.  
  420. /*
  421.  *----------------------------------------------------------------------
  422.  *
  423.  * SetHoleFileFD --
  424.  *
  425.  *    File 8
  426.  *    Nothing wrong here - just a file with a hole.
  427.  *
  428.  * Results:
  429.  *    None.
  430.  *
  431.  * Side effects:
  432.  *    None.
  433.  *
  434.  *----------------------------------------------------------------------
  435.  */
  436. void
  437. SetHoleFileFD(headerPtr, partFID, fileDescPtr)
  438.     register Fsdm_FileDescriptor *fileDescPtr;
  439.     Fsdm_DomainHeader *headerPtr;
  440.     int partFID;
  441. {
  442.     Time time;
  443.     int index;
  444.     char block[FS_BLOCK_SIZE];
  445.     int *indBlock = (int *) block;
  446.     int status;
  447.     int blockNum;
  448.  
  449.  
  450.     fileDescPtr->flags = FSDM_FD_ALLOC;
  451.     fileDescPtr->fileType = FS_FILE;
  452.     fileDescPtr->permissions = 0755;
  453.     fileDescPtr->uid = 0;
  454.     fileDescPtr->gid = 0;
  455.     fileDescPtr->lastByte = FSDM_NUM_DIRECT_BLOCKS * FS_BLOCK_SIZE +
  456.                 FSDM_INDICES_PER_BLOCK * FS_BLOCK_SIZE +
  457.                 1;
  458.     fileDescPtr->firstByte = -1;
  459.     fileDescPtr->numLinks = 1;
  460.     /*
  461.      * Can't know device information because that depends on
  462.      * the way the system is configured.
  463.      */
  464.     fileDescPtr->devServerID = -1;
  465.     fileDescPtr->devType = -1;
  466.     fileDescPtr->devUnit = -1;
  467.  
  468.     /*
  469.      * Set the time stamps.  This assumes that universal time, not local
  470.      * time, is used for time stamps.
  471.      */
  472.     Sys_GetTimeOfDay(&time, NULL, NULL);
  473.     fileDescPtr->createTime = time.seconds;
  474.     fileDescPtr->accessTime = 0;
  475.     fileDescPtr->descModifyTime = time.seconds;
  476.     fileDescPtr->dataModifyTime = time.seconds;
  477.  
  478.  
  479.     for (index = 0; index < FSDM_NUM_DIRECT_BLOCKS ; index++) {
  480.     fileDescPtr->direct[index] = FSDM_NIL_INDEX;
  481.     }
  482.     fileDescPtr->indirect[0] = FSDM_NIL_INDEX;
  483.     fileDescPtr->indirect[2] = FSDM_NIL_INDEX;
  484.     blockNum = 20 + FS_FRAGMENTS_PER_BLOCK * headerPtr->dataOffset ;
  485.     fileDescPtr->indirect[1] = blockNum;
  486.     indBlock[0] = blockNum + 4;
  487.     for (index = 1; index < FSDM_INDICES_PER_BLOCK;index++) {
  488.     indBlock[index] = FSDM_NIL_INDEX;
  489.     }
  490.     status = Disk_BlockWrite(partFID, headerPtr, headerPtr->dataOffset + 5,
  491.                  1, block);
  492.     if (status != SUCCESS) {
  493.     fprintf(stderr, "SetHoleFileFD : write failed.\n");
  494.     return;
  495.     }
  496.     blockNum += 4;
  497.     indBlock[0] = blockNum + 4 - FS_FRAGMENTS_PER_BLOCK * headerPtr->dataOffset;
  498.     for (index = 1; index < FSDM_INDICES_PER_BLOCK;index++) {
  499.     indBlock[index] = FSDM_NIL_INDEX;
  500.     }
  501.     status = Disk_BlockWrite(partFID, headerPtr, headerPtr->dataOffset + 6, 
  502.                  1, block);
  503.     if (status != SUCCESS) {
  504.     fprintf(stderr, "SetHoleFileFD : write failed.\n");
  505.     return;
  506.     }
  507.     fileDescPtr->numKbytes = 4;
  508.     fileDescPtr->version = 1;
  509. }
  510.  
  511. /*
  512.  *----------------------------------------------------------------------
  513.  *
  514.  * SetHoleDirFD --
  515.  *
  516.  *    File 9
  517.  *    Directory with a hole, which isn't allowed.
  518.  *
  519.  * Results:
  520.  *    None.
  521.  *
  522.  * Side effects:
  523.  *    None.
  524.  *
  525.  *----------------------------------------------------------------------
  526.  */
  527. void
  528. SetHoleDirFD(headerPtr, partFID, fileDescPtr)
  529.     register Fsdm_FileDescriptor *fileDescPtr;
  530.     Fsdm_DomainHeader *headerPtr;
  531.     int partFID;
  532. {
  533.     Time time;
  534.     int index;
  535.     char block[FS_BLOCK_SIZE];
  536.     int *indBlock = (int *) block;
  537.     int status;
  538.     int blockNum;
  539.  
  540.  
  541.     fileDescPtr->flags = FSDM_FD_ALLOC;
  542.     fileDescPtr->fileType = FS_DIRECTORY;
  543.     fileDescPtr->permissions = 0755;
  544.     fileDescPtr->uid = 0;
  545.     fileDescPtr->gid = 0;
  546.     fileDescPtr->lastByte = 2 * FS_BLOCK_SIZE -1;
  547.     fileDescPtr->firstByte = -1;
  548.     fileDescPtr->numLinks = 1;
  549.     /*
  550.      * Can't know device information because that depends on
  551.      * the way the system is configured.
  552.      */
  553.     fileDescPtr->devServerID = -1;
  554.     fileDescPtr->devType = -1;
  555.     fileDescPtr->devUnit = -1;
  556.  
  557.     /*
  558.      * Set the time stamps.  This assumes that universal time, not local
  559.      * time, is used for time stamps.
  560.      */
  561.     Sys_GetTimeOfDay(&time, NULL, NULL);
  562.     fileDescPtr->createTime = time.seconds;
  563.     fileDescPtr->accessTime = 0;
  564.     fileDescPtr->descModifyTime = time.seconds;
  565.     fileDescPtr->dataModifyTime = time.seconds;
  566.  
  567.  
  568.     fileDescPtr->direct[0] = 32;
  569.     fileDescPtr->direct[1] = FSDM_NIL_INDEX;
  570.     fileDescPtr->direct[2] = 36;
  571.     for (index = 3; index < FSDM_NUM_DIRECT_BLOCKS ; index++) {
  572.     fileDescPtr->direct[index] = FSDM_NIL_INDEX;
  573.     }
  574.     fileDescPtr->indirect[0] = FSDM_NIL_INDEX;
  575.     fileDescPtr->indirect[1] = FSDM_NIL_INDEX;
  576.     fileDescPtr->indirect[2] = FSDM_NIL_INDEX;
  577.     fileDescPtr->numKbytes = 1;
  578.     fileDescPtr->version = 1;
  579. }
  580.  
  581. /*
  582.  *----------------------------------------------------------------------
  583.  *
  584.  * SetBadEntryFileFD --
  585.  *
  586.  *    File 10.
  587.  *    The first indirect block contains an illegal index.
  588.  *    First direct block number is bad.
  589.  *
  590.  * Results:
  591.  *    None.
  592.  *
  593.  * Side effects:
  594.  *    None.
  595.  *
  596.  *----------------------------------------------------------------------
  597.  */
  598. void
  599. SetBadEntryFileFD(headerPtr, partFID, fileDescPtr)
  600.     register Fsdm_FileDescriptor *fileDescPtr;
  601.     Fsdm_DomainHeader *headerPtr;
  602.     int partFID;
  603. {
  604.     Time time;
  605.     int index;
  606.     char block[FS_BLOCK_SIZE];
  607.     int *indBlock = (int *) block;
  608.     int status;
  609.     int blockNum;
  610.  
  611.  
  612.     fileDescPtr->flags = FSDM_FD_ALLOC;
  613.     fileDescPtr->fileType = FS_FILE;
  614.     fileDescPtr->permissions = 0755;
  615.     fileDescPtr->uid = 0;
  616.     fileDescPtr->gid = 0;
  617.     fileDescPtr->lastByte = FSDM_NUM_DIRECT_BLOCKS * FS_BLOCK_SIZE +
  618.                 FSDM_INDICES_PER_BLOCK * FS_BLOCK_SIZE + 1;
  619.     fileDescPtr->firstByte = -1;
  620.     fileDescPtr->numLinks = 1;
  621.     /*
  622.      * Can't know device information because that depends on
  623.      * the way the system is configured.
  624.      */
  625.     fileDescPtr->devServerID = -1;
  626.     fileDescPtr->devType = -1;
  627.     fileDescPtr->devUnit = -1;
  628.  
  629.     /*
  630.      * Set the time stamps.  This assumes that universal time, not local
  631.      * time, is used for time stamps.
  632.      */
  633.     Sys_GetTimeOfDay(&time, NULL, NULL);
  634.     fileDescPtr->createTime = time.seconds;
  635.     fileDescPtr->accessTime = 0;
  636.     fileDescPtr->descModifyTime = time.seconds;
  637.     fileDescPtr->dataModifyTime = time.seconds;
  638.  
  639.     fileDescPtr->direct[0] = 10000000;
  640.     for (index = 1; index < FSDM_NUM_DIRECT_BLOCKS ; index++) {
  641.     fileDescPtr->direct[index] = FSDM_NIL_INDEX;
  642.     }
  643.     blockNum = 44 +  FS_FRAGMENTS_PER_BLOCK * headerPtr->dataOffset;
  644.     fileDescPtr->indirect[0] = blockNum;
  645.     bzero(block,FS_BLOCK_SIZE);
  646.  
  647.     indBlock[0] = 10000000;
  648.     for (index = 1; index < FSDM_INDICES_PER_BLOCK;index++) {
  649.     indBlock[index] = FSDM_NIL_INDEX;
  650.     }
  651.     status = Disk_BlockWrite(partFID, headerPtr,headerPtr->dataOffset + 11,  
  652.                  1, block);
  653.     if (status != SUCCESS) {
  654.     fprintf(stderr, "SetHoleFileFD : write failed.\n");
  655.     return;
  656.     }
  657.     blockNum = 48 +  FS_FRAGMENTS_PER_BLOCK * headerPtr->dataOffset;
  658.     fileDescPtr->indirect[1] = blockNum;
  659.     fileDescPtr->indirect[2] = FSDM_NIL_INDEX;
  660.     indBlock[0] = blockNum + 4;
  661.     for (index = 1; index < FSDM_INDICES_PER_BLOCK;index++) {
  662.     indBlock[index] = FSDM_NIL_INDEX;
  663.     }
  664.     status = Disk_BlockWrite(partFID, headerPtr,headerPtr->dataOffset + 12,
  665.                  1, block);
  666.     if (status != SUCCESS) {
  667.     fprintf(stderr, "SetHoleFileFD : write failed.\n");
  668.     return;
  669.     }
  670.     indBlock[0] = 56;
  671.     for (index = 1; index < FSDM_INDICES_PER_BLOCK;index++) {
  672.     indBlock[index] = FSDM_NIL_INDEX;
  673.     }
  674.     status = Disk_BlockWrite(partFID, headerPtr,headerPtr->dataOffset + 13 ,
  675.                  1, block);
  676.     if (status != SUCCESS) {
  677.     fprintf(stderr, "SetHoleFileFD : write failed.\n");
  678.     return;
  679.     }
  680.     fileDescPtr->numKbytes = 1;
  681.     fileDescPtr->version = 1;
  682. }
  683.  
  684. /*
  685.  *----------------------------------------------------------------------
  686.  *
  687.  * SetFragFileFD --
  688.  *
  689.  *    File 11
  690.  *    The first block is a fragment in the middle of a file.
  691.  *
  692.  * Results:
  693.  *    None.
  694.  *
  695.  * Side effects:
  696.  *    None.
  697.  *
  698.  *----------------------------------------------------------------------
  699.  */
  700. void
  701. SetFragFileFD(fileDescPtr)
  702.     register Fsdm_FileDescriptor *fileDescPtr;
  703. {
  704.     Time time;
  705.     int index;
  706.  
  707.  
  708.     fileDescPtr->flags = FSDM_FD_ALLOC;
  709.     fileDescPtr->fileType = FS_FILE;
  710.     fileDescPtr->permissions = 0755;
  711.     fileDescPtr->uid = 0;
  712.     fileDescPtr->gid = 0;
  713.     fileDescPtr->lastByte = FS_BLOCK_SIZE + FS_FRAGMENT_SIZE -1;
  714.     fileDescPtr->firstByte = -1;
  715.     fileDescPtr->numLinks = 1;
  716.     /*
  717.      * Can't know device information because that depends on
  718.      * the way the system is configured.
  719.      */
  720.     fileDescPtr->devServerID = -1;
  721.     fileDescPtr->devType = -1;
  722.     fileDescPtr->devUnit = -1;
  723.  
  724.     /*
  725.      * Set the time stamps.  This assumes that universal time, not local
  726.      * time, is used for time stamps.
  727.      */
  728.     Sys_GetTimeOfDay(&time, NULL, NULL);
  729.     fileDescPtr->createTime = time.seconds;
  730.     fileDescPtr->accessTime = 0;
  731.     fileDescPtr->descModifyTime = time.seconds;
  732.     fileDescPtr->dataModifyTime = time.seconds;
  733.  
  734.     fileDescPtr->direct[0] = 61;
  735.     fileDescPtr->direct[1] = 62;
  736.     for (index = 2; index < FSDM_NUM_DIRECT_BLOCKS ; index++) {
  737.     fileDescPtr->direct[index] = FSDM_NIL_INDEX;
  738.     }
  739.     for (index = 0; index < FSDM_NUM_INDIRECT_BLOCKS ; index++) {
  740.     fileDescPtr->indirect[index] = FSDM_NIL_INDEX;
  741.     }
  742.     fileDescPtr->numKbytes = 2;
  743.     fileDescPtr->version = 1;
  744. }
  745.  
  746. /*
  747.  *----------------------------------------------------------------------
  748.  *
  749.  * SetCopyFragFileFD --
  750.  *
  751.  *    File 12
  752.  *    The first direct block shares block 60  with file 11. 
  753.  *    The second direct block shares fragment 62  with file 11. 
  754.  *
  755.  * Results:
  756.  *    None.
  757.  *
  758.  * Side effects:
  759.  *    None.
  760.  *
  761.  *----------------------------------------------------------------------
  762.  */
  763. void
  764. SetCopyFragFileFD(fileDescPtr)
  765.     register Fsdm_FileDescriptor *fileDescPtr;
  766. {
  767.     Time time;
  768.     int index;
  769.  
  770.  
  771.     fileDescPtr->flags = FSDM_FD_ALLOC;
  772.     fileDescPtr->fileType = FS_FILE;
  773.     fileDescPtr->permissions = 0755;
  774.     fileDescPtr->uid = 0;
  775.     fileDescPtr->gid = 0;
  776.     fileDescPtr->lastByte = FS_BLOCK_SIZE + FS_FRAGMENT_SIZE -1;
  777.     fileDescPtr->firstByte = -1;
  778.     fileDescPtr->numLinks = 1;
  779.     /*
  780.      * Can't know device information because that depends on
  781.      * the way the system is configured.
  782.      */
  783.     fileDescPtr->devServerID = -1;
  784.     fileDescPtr->devType = -1;
  785.     fileDescPtr->devUnit = -1;
  786.  
  787.     /*
  788.      * Set the time stamps.  This assumes that universal time, not local
  789.      * time, is used for time stamps.
  790.      */
  791.     Sys_GetTimeOfDay(&time, NULL, NULL);
  792.     fileDescPtr->createTime = time.seconds;
  793.     fileDescPtr->accessTime = 0;
  794.     fileDescPtr->descModifyTime = time.seconds;
  795.     fileDescPtr->dataModifyTime = time.seconds;
  796.  
  797.     fileDescPtr->direct[0] = 60;
  798.     fileDescPtr->direct[1] = 62;
  799.     for (index = 2; index < FSDM_NUM_DIRECT_BLOCKS ; index++) {
  800.     fileDescPtr->direct[index] = FSDM_NIL_INDEX;
  801.     }
  802.     fileDescPtr->indirect[0] = FSDM_NIL_INDEX;
  803.     fileDescPtr->indirect[1] = FSDM_NIL_INDEX;
  804.     fileDescPtr->indirect[2] = FSDM_NIL_INDEX;
  805.     fileDescPtr->numKbytes = 4;
  806.     fileDescPtr->version = 1;
  807. }
  808.  
  809. /*
  810.  *----------------------------------------------------------------------
  811.  *
  812.  * SetCopyBlockFileFD --
  813.  *
  814.  *     File 13
  815.  *    Shares a block with file 10.
  816.  *    First indirect block number is bad.
  817.  *
  818.  * Results:
  819.  *    None.
  820.  *
  821.  * Side effects:
  822.  *    None.
  823.  *
  824.  *----------------------------------------------------------------------
  825.  */
  826. void
  827. SetCopyBlockFileFD(fileDescPtr)
  828.     register Fsdm_FileDescriptor *fileDescPtr;
  829. {
  830.     Time time;
  831.     int index;
  832.  
  833.     fileDescPtr->flags = FSDM_FD_ALLOC;
  834.     fileDescPtr->fileType = FS_FILE;
  835.     fileDescPtr->permissions = 0755;
  836.     fileDescPtr->uid = 0;
  837.     fileDescPtr->gid = 0;
  838.     fileDescPtr->lastByte =FSDM_NUM_DIRECT_BLOCKS * FS_BLOCK_SIZE +
  839.                 FSDM_INDICES_PER_BLOCK * FS_BLOCK_SIZE + 1 ;
  840.     fileDescPtr->firstByte = -1;
  841.     fileDescPtr->numLinks = 1;
  842.     /*
  843.      * Can't know device information because that depends on
  844.      * the way the system is configured.
  845.      */
  846.     fileDescPtr->devServerID = -1;
  847.     fileDescPtr->devType = -1;
  848.     fileDescPtr->devUnit = -1;
  849.  
  850.     /*
  851.      * Set the time stamps.  This assumes that universal time, not local
  852.      * time, is used for time stamps.
  853.      */
  854.     Sys_GetTimeOfDay(&time, NULL, NULL);
  855.     fileDescPtr->createTime = time.seconds;
  856.     fileDescPtr->accessTime = 0;
  857.     fileDescPtr->descModifyTime = time.seconds;
  858.     fileDescPtr->dataModifyTime = time.seconds;
  859.  
  860.     fileDescPtr->direct[0] = 56;
  861.     fileDescPtr->direct[1] = 0;
  862.     for (index = 2; index < FSDM_NUM_DIRECT_BLOCKS ; index++) {
  863.     fileDescPtr->direct[index] = FSDM_NIL_INDEX;
  864.     }
  865.     fileDescPtr->indirect[0] = 8;
  866.     fileDescPtr->indirect[1] = FSDM_NIL_INDEX;
  867.     fileDescPtr->indirect[2] = FSDM_NIL_INDEX;
  868.     fileDescPtr->numKbytes = 8;
  869.     fileDescPtr->version = 1;
  870. }
  871.  
  872. /*
  873.  *----------------------------------------------------------------------
  874.  *
  875.  * SetCopyIndBlockFileFD --
  876.  *
  877.  *     File 14
  878.  *    Shares an indirect block with file 10
  879.  *
  880.  * Results:
  881.  *    None.
  882.  *
  883.  * Side effects:
  884.  *    None.
  885.  *
  886.  *----------------------------------------------------------------------
  887.  */
  888. void
  889. SetCopyIndBlockFileFD(headerPtr, partFID, fileDescPtr)
  890.     register Fsdm_FileDescriptor *fileDescPtr;
  891.     Fsdm_DomainHeader *headerPtr;
  892.     int partFID;
  893. {
  894.     Time time;
  895.     int index;
  896.     int blockNum;
  897.  
  898.  
  899.     fileDescPtr->flags = FSDM_FD_ALLOC;
  900.     fileDescPtr->fileType = FS_FILE;
  901.     fileDescPtr->permissions = 0755;
  902.     fileDescPtr->uid = 0;
  903.     fileDescPtr->gid = 0;
  904.     fileDescPtr->lastByte = FSDM_NUM_DIRECT_BLOCKS * FS_BLOCK_SIZE +
  905.                 FSDM_INDICES_PER_BLOCK * FS_BLOCK_SIZE + 1;
  906.     fileDescPtr->firstByte = -1;
  907.     fileDescPtr->numLinks = 1;
  908.     /*
  909.      * Can't know device information because that depends on
  910.      * the way the system is configured.
  911.      */
  912.     fileDescPtr->devServerID = -1;
  913.     fileDescPtr->devType = -1;
  914.     fileDescPtr->devUnit = -1;
  915.  
  916.     /*
  917.      * Set the time stamps.  This assumes that universal time, not local
  918.      * time, is used for time stamps.
  919.      */
  920.     Sys_GetTimeOfDay(&time, NULL, NULL);
  921.     fileDescPtr->createTime = time.seconds;
  922.     fileDescPtr->accessTime = 0;
  923.     fileDescPtr->descModifyTime = time.seconds;
  924.     fileDescPtr->dataModifyTime = time.seconds;
  925.  
  926.  
  927.     for (index = 0; index < FSDM_NUM_DIRECT_BLOCKS ; index++) {
  928.     fileDescPtr->direct[index] = FSDM_NIL_INDEX;
  929.     }
  930.     fileDescPtr->indirect[0] = FSDM_NIL_INDEX;
  931.     blockNum = 48 +  FS_FRAGMENTS_PER_BLOCK * headerPtr->dataOffset;
  932.     fileDescPtr->indirect[1] = blockNum;
  933.     fileDescPtr->indirect[2] = FSDM_NIL_INDEX;
  934.     fileDescPtr->numKbytes = 4;
  935.     fileDescPtr->version = 1;
  936. }
  937.  
  938. /*
  939.  *----------------------------------------------------------------------
  940.  *
  941.  * SetCopyBogusIndBlockFileFD --
  942.  *
  943.  *     File 15
  944.  *    Shares an indirect block with file 10, but the block contains bogus
  945.  *        indices.
  946.  *
  947.  * Results:
  948.  *    None.
  949.  *
  950.  * Side effects:
  951.  *    None.
  952.  *
  953.  *----------------------------------------------------------------------
  954.  */
  955. void
  956. SetCopyBogusIndBlockFileFD(headerPtr, partFID, fileDescPtr)
  957.     register Fsdm_FileDescriptor *fileDescPtr;
  958.     Fsdm_DomainHeader *headerPtr;
  959.     int partFID;
  960. {
  961.     Time time;
  962.     int index;
  963.     int blockNum;
  964.  
  965.  
  966.     fileDescPtr->flags = FSDM_FD_ALLOC;
  967.     fileDescPtr->fileType = FS_FILE;
  968.     fileDescPtr->permissions = 0755;
  969.     fileDescPtr->uid = 0;
  970.     fileDescPtr->gid = 0;
  971.     fileDescPtr->lastByte = FSDM_NUM_DIRECT_BLOCKS * FS_BLOCK_SIZE +
  972.                 FSDM_INDICES_PER_BLOCK * FS_BLOCK_SIZE + 1;
  973.     fileDescPtr->firstByte = -1;
  974.     fileDescPtr->numLinks = 1;
  975.     /*
  976.      * Can't know device information because that depends on
  977.      * the way the system is configured.
  978.      */
  979.     fileDescPtr->devServerID = -1;
  980.     fileDescPtr->devType = -1;
  981.     fileDescPtr->devUnit = -1;
  982.  
  983.     /*
  984.      * Set the time stamps.  This assumes that universal time, not local
  985.      * time, is used for time stamps.
  986.      */
  987.     Sys_GetTimeOfDay(&time, NULL, NULL);
  988.     fileDescPtr->createTime = time.seconds;
  989.     fileDescPtr->accessTime = 0;
  990.     fileDescPtr->descModifyTime = time.seconds;
  991.     fileDescPtr->dataModifyTime = time.seconds;
  992.  
  993.  
  994.     for (index = 0; index < FSDM_NUM_DIRECT_BLOCKS ; index++) {
  995.     fileDescPtr->direct[index] = FSDM_NIL_INDEX;
  996.     }
  997.     fileDescPtr->indirect[0] = FSDM_NIL_INDEX;
  998.     blockNum = 56 +  FS_FRAGMENTS_PER_BLOCK * headerPtr->dataOffset;
  999.     fileDescPtr->indirect[1] = blockNum;
  1000.     fileDescPtr->indirect[2] = FSDM_NIL_INDEX;
  1001.     fileDescPtr->numKbytes = 1;
  1002.     fileDescPtr->version = 1;
  1003. }
  1004.  
  1005. /*
  1006.  *----------------------------------------------------------------------
  1007.  *
  1008.  * SetDirFD --
  1009.  *
  1010.  *    File 17    
  1011.  *    Set up a file descriptor for an empty directory
  1012.  *
  1013.  * Results:
  1014.  *    Fill in the file descriptor.
  1015.  *
  1016.  * Side effects:
  1017.  *    None.
  1018.  *
  1019.  *----------------------------------------------------------------------
  1020.  */
  1021. void
  1022. SetDirFD(fileDescPtr)
  1023.     register Fsdm_FileDescriptor *fileDescPtr;
  1024. {
  1025.     Time time;
  1026.     int index;
  1027.  
  1028.     fileDescPtr->flags =   FSDM_FD_ALLOC;
  1029.     fileDescPtr->fileType =  FS_DIRECTORY;
  1030.     fileDescPtr->permissions = 0755;
  1031.     fileDescPtr->uid = 0;
  1032.     fileDescPtr->gid = 0;
  1033.     fileDescPtr->lastByte = FSLCL_DIR_BLOCK_SIZE-1;
  1034.     fileDescPtr->firstByte = -1;
  1035.     fileDescPtr->numLinks = 0;
  1036.     /*
  1037.      * Can't know device information because that depends on
  1038.      * the way the system is configured.
  1039.      */
  1040.     fileDescPtr->devServerID = -1;
  1041.     fileDescPtr->devType = -1;
  1042.     fileDescPtr->devUnit = -1;
  1043.  
  1044.     /*
  1045.      * Set the time stamps.  This assumes that universal time, not local
  1046.      * time, is used for time stamps.
  1047.      */
  1048.     Sys_GetTimeOfDay(&time, NULL, NULL);
  1049.     fileDescPtr->createTime = time.seconds;
  1050.     fileDescPtr->accessTime = 0;
  1051.     fileDescPtr->descModifyTime = time.seconds;
  1052.     fileDescPtr->dataModifyTime = time.seconds;
  1053.  
  1054.     /*
  1055.      * Place the data in the first filesystem block.
  1056.      */
  1057.     fileDescPtr->direct[0] = 64;
  1058.     for (index = 1; index < FSDM_NUM_DIRECT_BLOCKS ; index++) {
  1059.     fileDescPtr->direct[index] = FSDM_NIL_INDEX;
  1060.     }
  1061.     for (index = 0; index < FSDM_NUM_INDIRECT_BLOCKS ; index++) {
  1062.     fileDescPtr->indirect[index] = FSDM_NIL_INDEX;
  1063.     }
  1064.     fileDescPtr->numKbytes = 1;
  1065.     fileDescPtr->version = 1;
  1066. }
  1067.  
  1068. /*
  1069.  *----------------------------------------------------------------------
  1070.  *
  1071.  * SetOutputFD --
  1072.  *
  1073.  *     File 18
  1074.  *
  1075.  * Results:
  1076.  *    None.
  1077.  *
  1078.  * Side effects:
  1079.  *    None.
  1080.  *
  1081.  *----------------------------------------------------------------------
  1082.  */
  1083. void
  1084. SetOutputFD(fileDescPtr)
  1085.     register Fsdm_FileDescriptor *fileDescPtr;
  1086. {
  1087.     Time time;
  1088.     int index;
  1089.     int blockNum;
  1090.  
  1091.  
  1092.     fileDescPtr->flags = FSDM_FD_ALLOC;
  1093.     fileDescPtr->fileType = FS_FILE;
  1094.     fileDescPtr->permissions = 0755;
  1095.     fileDescPtr->uid = 0;
  1096.     fileDescPtr->gid = 0;
  1097.     fileDescPtr->lastByte = 2 * FS_BLOCK_SIZE - 1;
  1098.     fileDescPtr->firstByte = -1;
  1099.     fileDescPtr->numLinks = 1;
  1100.     /*
  1101.      * Can't know device information because that depends on
  1102.      * the way the system is configured.
  1103.      */
  1104.     fileDescPtr->devServerID = -1;
  1105.     fileDescPtr->devType = -1;
  1106.     fileDescPtr->devUnit = -1;
  1107.  
  1108.     /*
  1109.      * Set the time stamps.  This assumes that universal time, not local
  1110.      * time, is used for time stamps.
  1111.      */
  1112.     Sys_GetTimeOfDay(&time, NULL, NULL);
  1113.     fileDescPtr->createTime = time.seconds;
  1114.     fileDescPtr->accessTime = 0;
  1115.     fileDescPtr->descModifyTime = time.seconds;
  1116.     fileDescPtr->dataModifyTime = time.seconds;
  1117.  
  1118.     fileDescPtr->direct[0] = 68;
  1119.     fileDescPtr->direct[1] = 72;
  1120.  
  1121.     for (index = 2; index < FSDM_NUM_DIRECT_BLOCKS ; index++) {
  1122.     fileDescPtr->direct[index] = FSDM_NIL_INDEX;
  1123.     }
  1124.     fileDescPtr->indirect[0] = FSDM_NIL_INDEX;
  1125.     fileDescPtr->indirect[1] = FSDM_NIL_INDEX;
  1126.     fileDescPtr->indirect[2] = FSDM_NIL_INDEX;
  1127.     fileDescPtr->numKbytes = 8;
  1128.     fileDescPtr->version = 1;
  1129. }
  1130.  
  1131. /*
  1132.  *----------------------------------------------------------------------
  1133.  *
  1134.  * SetBadDotDotFD --
  1135.  *
  1136.  *     File 21
  1137.  *    The ".." entry points to an unallocated file descriptor (22).
  1138.  *
  1139.  * Results:
  1140.  *    None.
  1141.  *
  1142.  * Side effects:
  1143.  *    None.
  1144.  *
  1145.  *----------------------------------------------------------------------
  1146.  */
  1147. void
  1148. SetBadDotDotFD(fileDescPtr)
  1149.     register Fsdm_FileDescriptor *fileDescPtr;
  1150. {
  1151.     Time time;
  1152.     int index;
  1153.     int blockNum;
  1154.  
  1155.  
  1156.     fileDescPtr->flags = FSDM_FD_ALLOC;
  1157.     fileDescPtr->fileType = FS_DIRECTORY;
  1158.     fileDescPtr->permissions = 0755;
  1159.     fileDescPtr->uid = 0;
  1160.     fileDescPtr->gid = 0;
  1161.     fileDescPtr->lastByte = FSLCL_DIR_BLOCK_SIZE-1;
  1162.     fileDescPtr->firstByte = -1;
  1163.     fileDescPtr->numLinks = 0;
  1164.     /*
  1165.      * Can't know device information because that depends on
  1166.      * the way the system is configured.
  1167.      */
  1168.     fileDescPtr->devServerID = -1;
  1169.     fileDescPtr->devType = -1;
  1170.     fileDescPtr->devUnit = -1;
  1171.  
  1172.     /*
  1173.      * Set the time stamps.  This assumes that universal time, not local
  1174.      * time, is used for time stamps.
  1175.      */
  1176.     Sys_GetTimeOfDay(&time, NULL, NULL);
  1177.     fileDescPtr->createTime = time.seconds;
  1178.     fileDescPtr->accessTime = 0;
  1179.     fileDescPtr->descModifyTime = time.seconds;
  1180.     fileDescPtr->dataModifyTime = time.seconds;
  1181.  
  1182.     fileDescPtr->direct[0] = 76;
  1183.  
  1184.     for (index = 1; index < FSDM_NUM_DIRECT_BLOCKS ; index++) {
  1185.     fileDescPtr->direct[index] = FSDM_NIL_INDEX;
  1186.     }
  1187.     fileDescPtr->indirect[0] = FSDM_NIL_INDEX;
  1188.     fileDescPtr->indirect[1] = FSDM_NIL_INDEX;
  1189.     fileDescPtr->indirect[2] = FSDM_NIL_INDEX;
  1190.     fileDescPtr->numKbytes = 1;
  1191.     fileDescPtr->version = 1;
  1192. }
  1193.  
  1194.  
  1195.